package demo6;


import java.util.*;


public class Test {
    public static void main(String[] args) {
        Set<User> users = DatabaseUtils.create();

        toMap(users);
    }
    private static void toMap(Set<User> users) {
        Map<String, Set<User>> setMap = new HashMap<>();
        for(User u : users){
            String city = u.getCity();
            if(setMap.get(city) == null) {
                setMap.put(u.getCity(), new HashSet<>());
            }
            setMap.get(city).add(u);
        }
        for(Map.Entry<String,Set<User>> s : setMap.entrySet() ){
            System.out.println(s.getKey());
            for(User user : s.getValue()){
                System.out.println(user.getId());
                System.out.println(user.getName());
            }
        }
    }
}
